// Matrix Addition Kernel
// C = A + B

struct Params {
    rows: u32,
    cols: u32,
    total_elements: u32,
}

@group(0) @binding(0) var<storage, read> A: array<f32>;
@group(0) @binding(1) var<storage, read> B: array<f32>;
@group(0) @binding(2) var<storage, read_write> C: array<f32>;
@group(0) @binding(3) var<uniform> params: Params;

@compute @workgroup_size(16, 16, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
    let row = global_id.y;
    let col = global_id.x;
    
    let idx = row * params.cols + col;
    
    // 边界检查
    if idx >= params.total_elements {
        return;
    }
    
    // 执行加法
    C[idx] = A[idx] + B[idx];
}